﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Web.UI;

namespace Catering
{
    public class View_Operaction_Common
    {
        //string[] strWeek = HttpContext.Current.Application["canbie"] as string[];
        //string[] canbie = HttpContext.Current.Application["strWeek"] as string[];
        string[] strWeek = new string[] { "星期一(Mon)", " 星期二(Tue)", "星期三(Wed)", "星期四(Thu)", " 星期五(Fri)", "星期六(sat)", "星期日(sun)" };
        string[] canbie = new string[] { "早餐", " 午餐", "晚餐", "夜餐" };
        #region 对话框
        public static void Show(Page page, string message)
        {
            ScriptManager.RegisterClientScriptBlock(page, typeof(Page), DateTime.Now.ToString().Replace(":", " "), "alert('" + message + "')", true);

        }
        #endregion
        #region 原料警戒线
        public Catering_Model.RoomWaing GetRaw_wring(string strGroupID, string strClassID, string strDBID, string strRaw)
        {
            Catering_Model.RoomWaing cmrw = null;
            DataSet ds_wring = new Catering_Rules.RoomWaing().GetAllList();
            DataSet ds_raw = new Catering_Rules.T_RawMaterial().GetList("InDBid='" + strRaw + "'");

            if (ds_wring != null && ds_wring.Tables.Count > 0 && ds_raw != null && ds_raw.Tables.Count > 0)
            {
                if (ds_wring.Tables[0] != null && ds_wring.Tables[0].Rows.Count > 0
                        && ds_raw.Tables[0] != null && ds_raw.Tables[0].Rows.Count > 0)
                {
                    var strInfo = from wing in ds_wring.Tables[0].AsEnumerable()

                                  where wing.Field<Int32>("RAWID") == Convert.ToInt32(ds_raw.Tables[0].Rows[0]["id"])
                                  where wing.Field<Int32>("GroupID") == Convert.ToInt32(strGroupID)
                                  where wing.Field<Int32>("ClassID") == Convert.ToInt32(strClassID)
                                  where wing.Field<Int32>("RoomID") == Convert.ToInt32(strDBID)

                                  select wing;
                    foreach (var item in strInfo)
                    {
                        DataRow dr = item as DataRow;
                        cmrw = new Catering_Rules.RoomWaing().GetModel(Convert.ToInt32(dr["id"]));
                    }

                }
            }
            return cmrw;

        }
        #endregion
        #region
        public string Get_Raw_MaxType_Id(string strTypeTableName, string strWhere)
        {
            string str_temp = "select * from " + strTypeTableName + " where " + strWhere;

            object obj = Catering_DBOpertion.DbHelperSQL.GetSingle(str_temp);
            if (obj != null)
            {
                return obj.ToString();
            }
            else
            {
                return "1";
            }

        }
        #endregion
        #region 下拉框
        public void DropDownListDataBind_BranchPost(DropDownList DL)
        {
            Catering_Rules.BranchPost operation = new Catering_Rules.BranchPost();
            DataSet Ds_BranchPost = operation.GetAllList();
            if (Ds_BranchPost != null)
            {
                if (Ds_BranchPost.Tables.Count > 0)
                {
                    DL.DataSource = Ds_BranchPost.Tables[0];
                    DL.DataTextField = "Name";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        public void DropDownListDataBind_MealTypes(DropDownList DL)
        {
            Catering_Rules.MealTypes operation = new Catering_Rules.MealTypes();
            DataSet Ds_OperationArea = operation.GetAllList();
            if (Ds_OperationArea != null)
            {
                if (Ds_OperationArea.Tables.Count > 0)
                {
                    DL.DataSource = Ds_OperationArea.Tables[0];
                    DL.DataTextField = "MealType";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        public void DropDownListDataBind_zhou(DropDownList ddl, string strDateList)
        {
            string[] strNumber = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };

            string[] strs = strDateList.Replace("'", "").Split(new char[] { '|', ' ' });
            Catering_DataSet.zhoulistDataTable zhou = new Catering_DataSet.zhoulistDataTable();
            int i = 0;
            if (strs.Length > 0)
            {
                if ((strs.Length - 1) % 7 == 0)
                {
                    i = (strs.Length - 1) / 7;
                }
                else
                {
                    i = (strs.Length - 1) / 7 + 1;
                }
            }
            for (int s = 0; s < i; s++)
            {
                DataRow dr = zhou.NewRow();
                dr["zhou"] = "第" + strNumber[s] + "周";
                dr["xuhao"] = s;
                zhou.Rows.Add(dr);

            }
            ddl.DataSource = zhou;
            ddl.DataTextField = "zhou";
            ddl.DataValueField = "xuhao";
            ddl.DataBind();
        }

        public void DropDownListDataBind_zhou(DropDownList ddl, DateTime strStat, DateTime strStop)
        {
            string[] strNumber = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };


            if (strStat != null && strStop != null)
            {
                TimeSpan ts = strStop - strStat;
                Catering_DataSet.zhoulistDataTable zhou = new Catering_DataSet.zhoulistDataTable();
                int i = 0;
                if (ts.Days > 0)
                {
                    if (ts.Days % 7 == 0)
                    {
                        i = ts.Days / 7;
                    }
                    else
                    {
                        i = ts.Days / 7 + 1;
                    }
                }
                for (int s = 0; s < i; s++)
                {
                    DataRow dr = zhou.NewRow();
                    dr["zhou"] = "第" + strNumber[s] + "周";
                    dr["xuhao"] = s;
                    zhou.Rows.Add(dr);

                }
                ddl.DataSource = zhou;
                ddl.DataTextField = "zhou";
                ddl.DataValueField = "xuhao";
                ddl.DataBind();
            }
        }
        /// <summary>
        /// 配餐人群
        /// </summary>
        /// <param name="DL"></param>
        public void DropDownListDataBind_Group_tedian(DropDownList DL)
        {
            Catering_Rules.Group_tedian operation = new Catering_Rules.Group_tedian();
            DataSet Ds_OperationArea = operation.GetAllList();
            if (Ds_OperationArea != null)
            {
                if (Ds_OperationArea.Tables.Count > 0)
                {
                    DL.DataSource = Ds_OperationArea.Tables[0];
                    DL.DataTextField = "PName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        /// <summary>
        /// 工作台下拉列表
        /// </summary>
        /// <param name="DL"></param>
        public void DropDownListDataBind_Group(DropDownList DL, int companyid)
        {
            Catering_Rules.OperationArea operation = new Catering_Rules.OperationArea();
            DataSet Ds_OperationArea = operation.GetAllListByCompanyID(companyid, true);
            if (Ds_OperationArea != null)
            {
                if (Ds_OperationArea.Tables.Count > 0)
                {
                    DL.DataSource = Ds_OperationArea.Tables[0];
                    DL.DataTextField = "AreaName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBind_Class(DropDownList DL, string GroupID)
        {
            Catering_Rules.ClassInfo info = new Catering_Rules.ClassInfo();
            DataSet Ds_ClassInfo = new DataSet();
            if (GroupID.Length < 1)
            {
                Ds_ClassInfo = info.GetList("1=1");
            }
            else
            {
                Ds_ClassInfo = info.GetList("AreaID=" + GroupID);
            }
            if (Ds_ClassInfo != null)
            {
                if (Ds_ClassInfo.Tables.Count > 0)
                {
                    DL.DataSource = Ds_ClassInfo.Tables[0];
                    DL.DataTextField = "CName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBind_Database(DropDownList DL, string GroupID, string ClassID)
        {
            Catering_Rules.StorageRoom info = new Catering_Rules.StorageRoom();
            DataSet Ds_ClassInfo = new DataSet();
            if (ClassID.Length < 1 && GroupID.Length <1)
            {
                Ds_ClassInfo = info.GetList("1=1");
            }
            else if (ClassID.Length < 1)
            {
                Ds_ClassInfo = info.GetList("GroupID=" + GroupID);
            }
            else
            {
                Ds_ClassInfo = info.GetList("GroupID=" + GroupID + " and  ClassID=" + ClassID);
            }
            if (Ds_ClassInfo != null)
            {
                if (Ds_ClassInfo.Tables.Count > 0)
                {
                    DL.DataSource = Ds_ClassInfo.Tables[0];
                    DL.DataTextField = "RoomID";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBind_library(DropDownList DL)
        {
            Catering_Rules.library info = new Catering_Rules.library();
            DataSet Ds_library = new DataSet();

            Ds_library = info.GetAllList();

            if (Ds_library != null)
            {
                if (Ds_library.Tables.Count > 0)
                {
                    DL.DataSource = Ds_library.Tables[0];
                    DL.DataTextField = "LName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBind_RawMaterials(DropDownList DL)
        {
            DropDownListDataBind_RawMaterials(DL, false);
        }

        public void DropDownListDataBind_RawMaterials(DropDownList DL, bool ishaveAll)
        {
            DL.Items.Clear();
            if (ishaveAll)
            {
                DL.Items.Add(new ListItem("全部", "-10"));
            }
            Catering_Rules.T_RawMaterials info = new Catering_Rules.T_RawMaterials();
            DataSet Ds_library = new DataSet();

            Ds_library = info.GetAllList();

            if (Ds_library != null)
            {
                if (Ds_library.Tables.Count > 0)
                {
                    if (ishaveAll)
                    {
                        if (Ds_library.Tables[0] != null && Ds_library.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow item in Ds_library.Tables[0].Rows)
                            {
                                string id = item["id"].ToString();
                                string name = item["TypeName"].ToString();
                                DL.Items.Add(new ListItem(name, id));
                            }
                            Ds_library.Tables[0].Dispose();
                        }
                    }
                    else
                    {
                        DL.DataSource = Ds_library.Tables[0];
                        DL.DataTextField = "TypeName";
                        DL.DataValueField = "id";
                        DL.DataBind();
                    }
                }
            }
        }

        public void DropDownListDataBind_RawMaterial(DropDownList DL, string strMax, string strMin)
        {
            Catering_Rules.T_RawMaterial info = new Catering_Rules.T_RawMaterial();
            DataSet Ds_RawMaterial = new DataSet();

            Ds_RawMaterial = info.GetList("RAWID=" + strMax + "  and RAWIDS=" + strMin);

            if (Ds_RawMaterial != null)
            {
                if (Ds_RawMaterial.Tables.Count > 0)
                {
                    DL.DataSource = Ds_RawMaterial.Tables[0];
                    DL.DataTextField = "RAWName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        public void DropDownListDataBind_RawMaterialsInfo(DropDownList DL, string strFMID)
        {
            Catering_Rules.RawMaterialsInfo info = new Catering_Rules.RawMaterialsInfo();
            DataSet Ds_library = new DataSet();

            Ds_library = info.GetList("RMID=" + strFMID);

            if (Ds_library != null)
            {
                if (Ds_library.Tables.Count > 0)
                {
                    DL.DataSource = Ds_library.Tables[0];
                    DL.DataTextField = "Name";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBind_RawMaterialsInfo(DropDownList DL, string strFMID, bool ishaveAll)
        {
            DL.Items.Clear();
            if (ishaveAll)
            {
                DL.Items.Add(new ListItem("全部", "-10"));
            }
            if (!string.IsNullOrEmpty(strFMID) && strFMID != "-10")
            {
                Catering_Rules.RawMaterialsInfo info = new Catering_Rules.RawMaterialsInfo();
                DataSet Ds_library = new DataSet();

                Ds_library = info.GetList("RMID=" + strFMID);

                if (Ds_library != null)
                {
                    if (Ds_library.Tables.Count > 0)
                    {
                        if (ishaveAll)
                        {
                            if (Ds_library.Tables[0] != null && Ds_library.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow item in Ds_library.Tables[0].Rows)
                                {
                                    string id = item["id"].ToString();
                                    string name = item["Name"].ToString();
                                    DL.Items.Add(new ListItem(name, id));
                                }
                                Ds_library.Tables[0].Dispose();
                            }
                        }
                        else
                        {
                            DL.DataSource = Ds_library.Tables[0];
                            DL.DataTextField = "Name";
                            DL.DataValueField = "id";
                            DL.DataBind();
                        }
                    }
                }
            }
        }

        public void DropDownListDataBind_Edible(DropDownList DL)
        {
            Catering_Rules.Edible info = new Catering_Rules.Edible();
            DataSet Ds_library = new DataSet();

            Ds_library = info.GetAllList();

            if (Ds_library != null)
            {
                if (Ds_library.Tables.Count > 0)
                {
                    DL.DataSource = Ds_library.Tables[0];
                    DL.DataTextField = "EName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBind_Water(DropDownList DL)
        {
            Catering_Rules.Water info = new Catering_Rules.Water();
            DataSet Ds_library = new DataSet();

            Ds_library = info.GetAllList();

            if (Ds_library != null)
            {
                if (Ds_library.Tables.Count > 0)
                {
                    DL.DataSource = Ds_library.Tables[0];
                    DL.DataTextField = "Name";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        public void DropDownListDataBind_DishType(DropDownList DL)
        {
            Catering_Rules.DishType crdt = new Catering_Rules.DishType();
            DataSet Ds_DishType = new DataSet();

            Ds_DishType = crdt.GetAllList();

            if (Ds_DishType != null)
            {
                if (Ds_DishType.Tables.Count > 0)
                {
                    DL.DataSource = Ds_DishType.Tables[0];
                    DL.DataTextField = "DT";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        public void DropDownListDataBing_Recipes(DropDownList DL)
        {
            Catering_Rules.T_Recipes crdt = new Catering_Rules.T_Recipes();
            DataSet Ds_DishType = new DataSet();

            Ds_DishType = crdt.GetAllList();

            if (Ds_DishType != null)
            {
                if (Ds_DishType.Tables.Count > 0)
                {
                    DL.DataSource = Ds_DishType.Tables[0];
                    DL.DataTextField = "CateringName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        public void DropDownListDataBind_DishTypes(DropDownList DL, string GroupID)
        {
            Catering_Rules.DishTypes info = new Catering_Rules.DishTypes();
            DataSet Ds_DishTypes = new DataSet();
            if (GroupID.Length < 1)
            {
                Ds_DishTypes = info.GetList("1=1");
            }
            else
            {
                Ds_DishTypes = info.GetList("DTID=" + GroupID);
            }
            if (Ds_DishTypes != null)
            {
                if (Ds_DishTypes.Tables.Count > 0)
                {
                    DL.DataSource = Ds_DishTypes.Tables[0];
                    DL.DataTextField = "DTName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        #endregion

        #region 入库管理

        /// <summary>
        /// 查找下拉表
        /// </summary>
        /// <param name="DL"></param>
        /// <param name="GroupID"></param>
        /// 
        public void DropDownListDataBind_ChaZhao(DropDownList DL)
        {
            Catering_Rules.OperationArea operation = new Catering_Rules.OperationArea();
            DataSet Ds_OperationArea = operation.GetAllList();
            if (Ds_OperationArea != null)
            {
                if (Ds_OperationArea.Tables.Count > 0)
                {
                    DL.DataSource = Ds_OperationArea.Tables[0];
                    DL.DataTextField = "AreaName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }

        /// <summary>
        /// 库房下拉表
        /// </summary>
        /// <param name="DL"></param>
        /// <param name="GroupID"></param>
        public void DropDownListDataBind_Kufang(DropDownList DL)
        {
            Catering_Rules.DBType operation = new Catering_Rules.DBType();
            DataSet Ds_OperationArea = operation.GetAllList();
            if (Ds_OperationArea != null)
            {
                if (Ds_OperationArea.Tables.Count > 0)
                {
                    DL.DataSource = Ds_OperationArea.Tables[0];
                    DL.DataTextField = "DTName";
                    DL.DataValueField = "id";
                    DL.DataBind();
                }
            }
        }
        #endregion

        #region 出库管理

        //public void DropDownListDataBind_Chuku(DropDownList DL,Name1,Name2,Name3)
        //{
        //    Catering_Rules.FromRecords operation = new Catering_Rules.FromRecords();
        //    DataSet Ds_OperationArea = operation.GetAllList();
        //    if (Ds_OperationArea != null)
        //    {
        //        if (Ds_OperationArea.Tables.Count > 0)
        //        {
        //            DL.DataSource = Ds_OperationArea.Tables[0];
        //            DL.DataTextField = Name1;
        //            DL.DataTextField = "ClassID";
        //            DL.DataTextField = "DBID";
        //            DL.DataValueField = "id";
        //            DL.DataBind();
        //        }
        //    }
        //}

        #endregion

        #region 食谱

        //星期一至星期五的数据
        public string Getshipu(string strStatDate, DataTable dt = null, int weeklength = 0)
        {



            int i = 0;
            string weekday = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(strStatDate).DayOfWeek);
            for (int j = 0; j < 7; j++)
            {
                if (strWeek[j].IndexOf(weekday) > -1)
                {
                    i = j + 1;
                    break;
                }
            }
            System.Text.StringBuilder stsb = new System.Text.StringBuilder();
            stsb.Append("<table border=\"1\" style=\"width:300px;background-color:#dbf4df;\" id=\"pgriddivshipuarea\" class=\"pgridtable\" border=\"0\"  cellspacing=\"0\" cellpadding=\"0\">");
            stsb.Append("<thead>");
            stsb.Append("<tr>");
            stsb.Append("<th style=\"cursor: pointer\" class=\"pgridtd\" rowspan=\"2\"  thcol=\"0\" >餐别  </th>");
            stsb.Append("<th style=\"height: 30px; cursor: default\" class=\"pgridtd\" colspan=\"2\" thcol=\"" + i + "\">" + strWeek[i - 1] + "</th>");
            stsb.Append(" </tr>");
            stsb.Append("</thead>");
            stsb.Append(" <tbody id=\"aaa_bbb\">");
            for (int t = 0; t < canbie.Length; t++)
            {
                int can = t + 1;
                stsb.Append("<tr style=\"height: 100px\" id=\"1\"  cid=\"divshipuarea\" mid=\"" + can + "\">");
                stsb.Append(" <td width=\"30%\" id=\"" + can + "\"style=\"cursor: pointer\" class=\"pgridtd\" cid=\"divshipuarea\" mid=\"+can+\"ism=\"1\">" + canbie[t] + "</td>");
                int one = i;
                string strdate = Convert.ToDateTime(strStatDate).AddDays(i).ToShortDateString();
                stsb.Append(" <td width=\"30%\" id=\"Dish" + strStatDate + ":" + one + "_" + can + "\" valign=\"top\" cid=\"divshipuarea\"isdm=\"true\" mid=\"" + can + "\" dayno=\"0\" istz=\"true\" tzid=\"-" + i + "-" + can + "\" > ");
                DataRow[] drs = new DataRow[] { };
                if (dt != null && dt.Rows.Count > 0)
                {
                    drs = dt.Select("canbie=" + can);
                    if (drs.Length > 0)
                    {
                        for (int m = 0; m < drs.Length; m++)
                        {
                            string caiinfo = Getcai(drs[m]["W" + one].ToString(), can.ToString(), strdate);
                            stsb.Append(caiinfo);
                        }
                    }
                }
                stsb.Append("</td>");
                stsb.Append("<td width=\"40%\" id=\"Element" + strStatDate + ":" + one + "_" + can + "\" valign=\"top\" cid=\"divshipuarea\"mid=\"" + can + "\" dayno=\"0\" istz=\"true\" tzid=\"-" + i + "-" + can + "\">");
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (drs.Length > 0)
                    {
                        for (int m = 0; m < drs.Length; m++)
                        {
                            if (drs[m]["W" + one].ToString().Length > 0)
                            {
                                string hanliang = GetHanliang(drs[m]["W" + one].ToString(), can.ToString(), strdate);
                                stsb.Append(hanliang);
                            }
                        }
                    }
                }
                stsb.Append("</td>");
                stsb.Append("</tr>");
            }
            stsb.Append(" </tbody>");
            stsb.Append("</table>");
            return stsb.ToString();
        }
        public Int32 GetWeekNumber(string strDate)
        {
            string weekday = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(strDate).DayOfWeek);
            int i = 0;
            for (int j = 0; j < 7; j++)
            {
                if (strWeek[j].IndexOf(weekday) > -1)
                {
                    i = j + 1;
                    break;
                }
            }
            return i;
        }
        public string Getshipu(string strStatDate, DataTable dt)
        {



            int i = 0;
            string weekday = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(strStatDate).DayOfWeek);
            for (int j = 0; j < 7; j++)
            {
                if (strWeek[j].IndexOf(weekday) > -1)
                {
                    i = j + 1;
                    break;
                }
            }
            System.Text.StringBuilder stsb = new System.Text.StringBuilder();
            stsb.Append("<table border=\"1\" style=\"width:300px;background-color:#dbf4df;\" id=\"pgriddivshipuarea\" class=\"pgridtable\" border=\"0\"  cellspacing=\"0\" cellpadding=\"0\">");
            stsb.Append("<thead>");
            stsb.Append("<tr>");
            stsb.Append("<th style=\"cursor: pointer\" class=\"pgridtd\" rowspan=\"2\"  thcol=\"0\" >餐别  </th>");
            stsb.Append("<th style=\"height: 30px; cursor: default\" class=\"pgridtd\" colspan=\"2\" thcol=\"" + i + "\">" + strWeek[i - 1] + "</th>");
            stsb.Append(" </tr>");
            stsb.Append("</thead>");
            stsb.Append(" <tbody id=\"aaa_bbb\">");
            for (int t = 0; t < canbie.Length; t++)
            {
                int can = t + 1;
                stsb.Append("<tr style=\"height: 100px\" id=\"1\"  cid=\"divshipuarea\" mid=\"" + can + "\">");
                stsb.Append(" <td width=\"30%\" id=\"" + can + "\"style=\"cursor: pointer\" class=\"pgridtd\" cid=\"divshipuarea\" mid=\"+can+\"ism=\"1\">" + canbie[t] + "</td>");
                int one = i;

                stsb.Append(" <td width=\"30%\" id=\"Dish" + strStatDate + ":" + one + "_" + can + "\" valign=\"top\" cid=\"divshipuarea\"isdm=\"true\" mid=\"" + can + "\" dayno=\"0\" istz=\"true\" tzid=\"-" + i + "-" + can + "\" > ");
                DataRow[] drs = new DataRow[] { };
                if (dt != null && dt.Rows.Count > 0)
                {
                    drs = dt.Select("canbie=" + can);
                    if (drs.Length > 0)
                    {
                        for (int m = 0; m < drs.Length; m++)
                        {
                            string caiinfo = Getcai(drs[m]["W" + one].ToString(), can.ToString(), strStatDate);
                            stsb.Append(caiinfo);
                        }
                    }
                }
                stsb.Append("</td>");
                stsb.Append("<td width=\"40%\" id=\"Element" + strStatDate + ":" + one + "_" + can + "\" valign=\"top\" cid=\"divshipuarea\"mid=\"" + can + "\" dayno=\"0\" istz=\"true\" tzid=\"-" + i + "-" + can + "\">");
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (drs.Length > 0)
                    {
                        for (int m = 0; m < drs.Length; m++)
                        {
                            if (drs[m]["W" + one].ToString().Length > 0)
                            {
                                string hanliang = GetHanliang(drs[m]["W" + one].ToString(), can.ToString(), strStatDate);
                                stsb.Append(hanliang);
                            }
                        }
                    }
                }
                stsb.Append("</td>");
                stsb.Append("</tr>");
            }
            stsb.Append(" </tbody>");
            stsb.Append("</table>");
            return stsb.ToString();
        }

        //全部的框架、以及数据
        public string Getshipu(string strStatDate, int IntWeekLength, DataTable dt)
        {


            int i = 0;
            string weekday = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(strStatDate).DayOfWeek);
            for (int j = 0; j < 7; j++)
            {
                if (strWeek[j].IndexOf(weekday) > -1)
                {
                    i = j + 1;
                    break;
                }
            }

            System.Text.StringBuilder stsb = new System.Text.StringBuilder();
            stsb.Append("<table border=\"1\" style=\"width:100%;background-color:#dbf4df;\" id=\"pgriddivshipuarea\" class=\"pgridtable\" border=\"0\"  cellspacing=\"0\" cellpadding=\"0\">");
            stsb.Append("<thead>");
            stsb.Append("<tr>");
            stsb.Append("<th style=\"cursor: pointer\" class=\"pgridtd\" rowspan=\"2\"  thcol=\"0\" >餐别  </th>");

            for (int w = 0; w < IntWeekLength; w++)
            {
                stsb.Append("<th style=\"height: 30px; cursor: default\" class=\"pgridtd\" colspan=\"2\" thcol=\"" + w + "\">" + strWeek[w] + "</th>");
            }
            stsb.Append(" </tr>");
            stsb.Append("</thead>");
            stsb.Append(" <tbody id=\"aaa_bbb\">");
            for (int t = 0; t < canbie.Length; t++)
            {
                int can = t + 1;
                stsb.Append("<tr style=\"height: 100px\" id=\"1\"  cid=\"divshipuarea\" mid=\"" + can + "\">");
                stsb.Append(" <td id=\"" + can + "\"style=\"cursor: pointer;\" width=\"10%\" class=\"pgridtd\" cid=\"divshipuarea\" mid=\"+can+\"ism=\"1\">" + canbie[t] + "</td>");

                for (int d = 0; d < IntWeekLength; d++)
                {
                    int one = d + 1;
                    string strdate = Convert.ToDateTime(strStatDate).AddDays(d).ToShortDateString();
                    stsb.Append(" <td width=\"10%\" id=\"Dish" + strStatDate + ":" + one + "_" + can + "\" valign=\"top\" cid=\"divshipuarea\"isdm=\"true\" mid=\"" + can + "\" dayno=\"0\" istz_two=\"true\" bid=\"" + strStatDate + ":" + one + "_" + can + "\"> ");
                    DataRow[] drs = dt.Select("canbie=" + can);
                    if (drs.Length > 0)
                    {
                        for (int m = 0; m < drs.Length; m++)
                        {
                            string caiinfo = Getcai(drs[m]["W" + one].ToString(), can.ToString(), strStatDate);
                            stsb.Append(caiinfo);
                        }
                    }

                    stsb.Append("</td>");
                    stsb.Append("<td width=\"10%\" id=\"Element" + strStatDate + ":" + one + "_" + can + "\" valign=\"top\" cid=\"divshipuarea\"mid=\"" + can + "\" dayno=\"0\" istz_two=\"true\" bid=\"" + strStatDate + ":" + one + "_" + can + "\">");
                    if (drs.Length > 0)
                    {
                        for (int m = 0; m < drs.Length; m++)
                        {
                            if (drs[m]["W" + one].ToString().Length > 0)
                            {
                                string hanliang = GetHanliang(drs[m]["W" + one].ToString(), can.ToString(), strStatDate);
                                stsb.Append(hanliang);
                            }
                        }
                    }

                    stsb.Append("</td>");
                }

                stsb.Append("</tr>");
            }
            stsb.Append(" </tbody>");
            stsb.Append("</table>");

            return stsb.ToString();
        }
        #region 食谱呈现表换成对象集合
        public List<Catering_Model.E_RecipeInformation> GetTableToList(DataTable dt_show, DateTime NowDate)
        {
            List<Catering_Model.E_RecipeInformation> list = new List<Catering_Model.E_RecipeInformation>();
            if (dt_show != null && dt_show.Rows.Count > 0)
            {
                for (int i = 1; i <= 4; i++)
                {
                    DataRow[] drcanbie = dt_show.Select("canbie=" + i);
                    if (drcanbie.Length > 0)
                    {
                        foreach (DataRow dr in drcanbie)
                        {
                            for (int j = 1; j <= dt_show.Columns.Count - 1; j++)
                            {
                                //int NoWeek = 0;
                                DateTime dtadd = NowDate.AddDays(j - 1);
                                //NoWeek = new Catering_Rules.RecipesWeek().GetNumber(dtadd);
                                if (dr["W" + j] != null && dr["W" + j].ToString().Length > 0)
                                {
                                    Catering_Model.E_RecipeInformation cmpi = new Catering_Model.E_RecipeInformation();
                                    cmpi.FMID = i;
                                    cmpi.Date = dtadd;
                                    cmpi.CID = Convert.ToInt32(dr["W" + j].ToString());
                                    cmpi.Week = GetWeekNumber(dtadd.ToShortDateString());
                                    cmpi.AVGWeight = "1";
                                    cmpi.Price = 1;
                                    cmpi.Weight = "1";
                                    //cmpi.temp1 = NoWeek.ToString();
                                    list.Add(cmpi);

                                }
                            }
                        }
                    }
                }
            }
            return list;
        }
        #endregion
        #region 食谱表信息
        /// <summary>
        ///  获取食谱表
        /// </summary>
        /// <param name="strDate"></param>
        /// <returns></returns>

        public DataTable GetshipuInfo(string strDate, string strWhere, Int32 weeklength)
        {
            DataTable dt_recipe = new Catering_DataSet.recipeInfoDataTable();
            Catering_Rules.T_RecipeInformation crri = new Catering_Rules.T_RecipeInformation();
            DataSet ds = crri.GetList(strWhere);
            ArrayList listlength = new ArrayList();
            ArrayList list = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < weeklength; i++)
                {
                    DataRow[] dr1 = dt.Select("date ='" + Convert.ToDateTime(strDate).AddDays(i).ToShortDateString() + "'");
                    listlength.Add(dr1.Length);
                    list.Add(dr1);
                }
                listlength.Sort();
                if (listlength.Count > 0)
                {

                    for (int j = 0; j < Convert.ToInt32(listlength[listlength.Count - 1]); j++)
                    {
                        DataRow dr = dt_recipe.NewRow();

                        for (int s = 0; s < weeklength; s++)
                        {
                            if ((list[s] as DataRow[]).Length > 0 && j < (list[s] as DataRow[]).Length)
                            {
                                DataRow drs = (list[s] as DataRow[])[j];
                                int t = s + 1;

                                if (drs != null)
                                {
                                    if (drs["Week"].Equals(t))
                                    {

                                        dr["canbie"] = drs["FMID"];
                                        dr["w" + t] = drs["CID"];
                                    }
                                }
                                else
                                {
                                    dr["w" + t] = "";
                                }
                            }
                        }
                        dt_recipe.Rows.Add(dr);
                    }
                }
            }
            return dt_recipe;
        }

        public DataTable GetshipuInfo(string strArearID, string strClassID, Int32 weeklength, string strtedian = null)
        {
            DataTable dt_recipeCom = new Catering_DataSet.recipeInfoDataTable();
            Catering_Rules.RecipesComtemptle crri = new Catering_Rules.RecipesComtemptle();
            string strWhere = string.Empty;
            if (strtedian != null && strtedian.Length > 0)
            {
                strWhere = "AreaID=" + strArearID + "  and ClassID=" + strClassID + "  and TName='" + strtedian + "'";
            }
            else
            {
                strWhere = "AreaID=" + strArearID + "  and ClassID=" + strClassID + "  and Tid= 7 ";
            }
            DataSet ds = crri.GetList(strWhere);
            ArrayList listlength = new ArrayList();
            ArrayList list = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                for (int i = 01; i <= weeklength; i++)
                {
                    DataRow[] dr1 = dt.Select("WeekId=" + i);
                    listlength.Add(dr1.Length);
                    list.Add(dr1);
                }
                listlength.Sort();

                for (int j = 0; j < Convert.ToInt32(listlength[listlength.Count - 1]); j++)
                {
                    DataRow dr = dt_recipeCom.NewRow();

                    for (int s = 0; s < weeklength; s++)
                    {
                        if ((list[s] as DataRow[]).Length > 0 && j < (list[s] as DataRow[]).Length)
                        {
                            DataRow drs = (list[s] as DataRow[])[j];
                            int t = s + 1;

                            if (drs != null)
                            {
                                if (drs["WeekId"].Equals(t))
                                {

                                    dr["canbie"] = drs["canbie"];
                                    dr["w" + t] = drs["DishID"];
                                }
                            }
                            else
                            {
                                dr["w" + t] = "";
                            }
                        }
                    }
                    dt_recipeCom.Rows.Add(dr);
                }
            }
            return dt_recipeCom;
        }
        #endregion
        #region 食谱内容
        public string GetHanliang(string Dish_ID, string strCanBie = "", string strdate = "")
        {
            System.Text.StringBuilder stsb = new System.Text.StringBuilder();
            stsb.Append("<div style=\"margin-top: 4px; height: 72px; cursor: pointer;\"  CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\" Is_tzcai=\"true\">");
            Catering_Rules.T_DishInfo crd = new Catering_Rules.T_DishInfo();
            if (crd.GetModelList("DID=" + Dish_ID).Count > 0)
            {
                foreach (Catering_Model.E_DishInfo di in crd.GetModelList("DID=" + Dish_ID))
                {
                    stsb.Append("<div style=\"width: 100%; white-space: nowrap; height: 18px\" CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\" >");
                    stsb.Append("<span style=\"float: left; margin-left: 5px\" class=\"pgridblabel\" CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\" >" + di.DName + "</span>");
                    stsb.Append("<span style=\"float: right; margin-right: 5px;\" CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\">" + di.Content + "</span>");
                    stsb.Append("</div>");
                }
            }
            stsb.Append("</div >");
            return stsb.ToString();

        }
        public string Getcai(string Dish_ID, string strCanBie, string strdate = "")
        {

            System.Text.StringBuilder stsb = new System.Text.StringBuilder();
            Catering_Rules.T_Dish crd = new Catering_Rules.T_Dish();
            if (Dish_ID.Length > 0 && strCanBie.Length > 0)
            {
                string strName = crd.GetModel(Convert.ToInt32(Dish_ID)).Name;
                string[] canbie = strCanBie.Split(new char[] { '-' });

                stsb.Append("<div style=\"text-align: left; margin-top: 4px; height: 72px; display:block; cursor: pointer\" id=\"divs" + Dish_ID + "\" class=\"pgridadivss\" CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\" Is_tzcai=\"true\">");
                stsb.Append("<span style=\"float: left; margin-left: 5px\" class=\"pgridalabel\" CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\">" + strName + "</span>");
                stsb.Append("<span style=\"float: right; margin-left: 3px; margin-right: 5px\" class=\"pgridalabel\"");
                stsb.Append("cid=\"divshipuarea\" CaiID=\"" + strdate + "|" + Dish_ID + "|" + strCanBie + "\">" + Dish_ID + "</span>");
                stsb.Append("</div>");

            }

            return stsb.ToString();

        }
        #endregion
        #endregion

        #region 树形结构

        #region 菜品树形结构
        public DataTable TreeViewDataBind_Library()
        {
            Catering_Rules.library crl = new Catering_Rules.library();
            DataSet ds_library = crl.GetAllList();
            DataTable dt = new DataTable();
            if (ds_library != null)
            {
                if (ds_library.Tables.Count > 0)
                {

                    dt = ds_library.Tables[0];
                }
            }
            return dt;
        }
        public void TreeViewDataBind_Library(DataList Dl)
        {
            Catering_Rules.library crl = new Catering_Rules.library();
            DataSet ds_library = crl.GetAllList();
            if (ds_library != null)
            {
                if (ds_library.Tables.Count > 0)
                {
                    Dl.DataSource = ds_library.Tables[0];
                    //Dl.DataMember = "LName";
                    //Dl.DataKeyField = "id";
                    Dl.DataBind();
                }
            }
        }
        public void TreeViewDataBind_DishTypes(TreeView tv, string strLibraryID)
        {
            tv.Nodes.Clear();
            Catering_Rules.DishTypes crdt = new Catering_Rules.DishTypes();
            DataSet ds_DishTypes = crdt.GetList("DTID=" + strLibraryID);

            if (ds_DishTypes != null)
            {
                if (ds_DishTypes.Tables.Count > 0)
                {
                    foreach (DataRow dr_DishTyps in ds_DishTypes.Tables[0].Rows)
                    {
                        if (dr_DishTyps["DTName"] != null)
                        {
                            TreeNode tn = new TreeNode();
                            tn.Text = dr_DishTyps["DTName"].ToString();
                            tn.Value = dr_DishTyps["id"].ToString();
                            tn.Target = "type";
                            //--------------添加子节点-----------------------------------//
                            TreeViewDataBing_Dish(tn, dr_DishTyps["id"].ToString());
                            tv.Nodes.Add(tn);
                        }

                    }
                }
            }
        }
        private void TreeViewDataBing_Dish(TreeNode tn, string strDishTypsID)
        {
            Catering_Rules.T_Dish crd = new Catering_Rules.T_Dish();
            DataSet ds_Dish = crd.GetList("DTID=" + strDishTypsID);
            if (ds_Dish != null)
            {
                if (ds_Dish.Tables.Count > 0)
                {
                    foreach (DataRow dr_Dish in ds_Dish.Tables[0].Rows)
                    {
                        if (dr_Dish["Name"] != null)
                        {
                            TreeNode tn_Dish = new TreeNode();
                            tn_Dish.Text = dr_Dish["Name"].ToString();
                            tn_Dish.Value = dr_Dish["id"].ToString();
                            tn.ChildNodes.Add(tn_Dish);
                        }
                    }
                }
            }

        }
        public string UITreeViewDataBind_DishTypes(string strLibraryID)
        {

            Catering_Rules.DishTypes crdt = new Catering_Rules.DishTypes();
            DataSet ds_DishTypes = crdt.GetList("DTID=" + strLibraryID);
            System.Text.StringBuilder sbUi = new System.Text.StringBuilder();
            sbUi.Append("<ul>");
            if (ds_DishTypes != null)
            {
                if (ds_DishTypes.Tables.Count > 0)
                {
                    Int32 inti = 0;
                    foreach (DataRow dr_DishTyps in ds_DishTypes.Tables[0].Rows)
                    {
                        if (dr_DishTyps["DTName"] != null)
                        {
                            inti++;
                            sbUi.Append(" <li id=\"treeview_list\"> ");
                            sbUi.Append(" <a uid=\"" + dr_DishTyps["id"].ToString() + "\">" + dr_DishTyps["DTName"].ToString() + "</a>");
                            //--------------添加子节点-----------------------------------//
                            UITreeViewDataBing_Dish(inti, sbUi, dr_DishTyps["id"].ToString());
                            sbUi.Append(" </li>");
                        }
                    }
                }
            }
            sbUi.Append("</li>");
            sbUi.Append("</ul>");
            return sbUi.ToString();
        }


        public void UITreeViewDataBing_Dish(int i, System.Text.StringBuilder sbUi, string strDishTypsID)
        {
            Catering_Rules.T_Dish crd = new Catering_Rules.T_Dish();
            DataSet ds_Dish = crd.GetList("DTID=" + strDishTypsID);
            sbUi.Append("<ul class=\"treeview\">");
            if (ds_Dish != null)
            {
                if (ds_Dish.Tables.Count > 0)
                {
                    foreach (DataRow dr_Dish in ds_Dish.Tables[0].Rows)
                    {
                        if (dr_Dish["Name"] != null)
                        {
                            sbUi.Append("<li>");
                            sbUi.Append("<a uid=\"" + dr_Dish["id"].ToString() + "\">");
                            sbUi.Append(dr_Dish["Name"].ToString());
                            sbUi.Append("</a>");
                            sbUi.Append("</li>");
                        }
                    }
                }
            }
            sbUi.Append("</ul>");

        }
        #endregion

        #region 原料树形结构
        public string UIDataBing_RawMaterials()
        {
            string strUi_Root = string.Empty;
            Catering_Rules.T_RawMaterials crr = new Catering_Rules.T_RawMaterials();
            DataSet ds_RawMaterials = crr.GetAllList();
            System.Text.StringBuilder sbUi = new System.Text.StringBuilder();
            sbUi.Append("<ul  id=\"browser\" class=\"filetree\"> ");
            if (ds_RawMaterials != null)
            {
                if (ds_RawMaterials.Tables.Count > 0)
                {
                    Int32 inti = 0;
                    foreach (DataRow dr_RawMaterials in ds_RawMaterials.Tables[0].Rows)
                    {
                        if (dr_RawMaterials["TypeName"] != null)
                        {
                            inti++;
                            sbUi.Append("<li> ");
                            sbUi.Append(" <span class=\"folder\" id =\"" + dr_RawMaterials["id"].ToString() + "\"> ");

                            sbUi.Append(" " + dr_RawMaterials["TypeName"].ToString() + " ");
                            sbUi.Append(" </span>");

                            //--------------添加子节点-----------------------------------//
                            UIDataBing_RawMaterialsInfo(inti, sbUi, dr_RawMaterials["id"].ToString());

                            sbUi.Append(" </li>");


                        }
                    }
                }
            }

            sbUi.Append("     </ul>");
            return sbUi.ToString();
        }
        private void UIDataBing_RawMaterialsInfo(int i, System.Text.StringBuilder sbUi, string tvNodeId)
        {
            Catering_Rules.RawMaterialsInfo crr = new Catering_Rules.RawMaterialsInfo();
            DataSet ds_RawMaterialsInfo = crr.GetList("RMID=" + tvNodeId);
            Int32 inti = 1;
            sbUi.Append("<ul id=\"Ul" + i + "\"> ");

            if (ds_RawMaterialsInfo != null)
            {
                if (ds_RawMaterialsInfo.Tables.Count > 0)
                {
                    foreach (DataRow dr_RawMaterialsInfo in ds_RawMaterialsInfo.Tables[0].Rows)
                    {
                        if (dr_RawMaterialsInfo["Name"] != null)
                        {
                            sbUi.Append("<li> ");

                            sbUi.Append(" <span class=\"folder\"> ");
                            sbUi.Append("  " + dr_RawMaterialsInfo["Name"].ToString() + " ");
                            sbUi.Append("  </span >");

                            UIViewDataBing_RawMaterial(sbUi, dr_RawMaterialsInfo["id"].ToString());

                            sbUi.Append("  </li>");

                        }
                        inti++;
                    }
                }
            }

            sbUi.Append("     </ul>");
        }
        private void UIViewDataBing_RawMaterial(System.Text.StringBuilder sbUi, string strNodeId)
        {
            Catering_Rules.T_RawMaterial crr = new Catering_Rules.T_RawMaterial();
            Catering_Rules.ViewOperaction crv = new Catering_Rules.ViewOperaction();

            DataSet ds_RawMaterial = crr.GetList("RAWIDS=" + strNodeId);
            sbUi.Append("<ul> ");


            if (ds_RawMaterial != null)
            {
                if (ds_RawMaterial.Tables.Count > 0)
                {
                    foreach (DataRow dr_RawMaterial in ds_RawMaterial.Tables[0].Rows)
                    {
                        if (dr_RawMaterial["RAWName"] != null)
                        {
                            sbUi.Append("<li> ");

                            sbUi.Append("  <span class=\"file\">");



                            sbUi.Append("  " + dr_RawMaterial["RAWName"].ToString() + " ");
                            sbUi.Append("  </span>");
                            sbUi.Append("  </li>");

                        }
                    }
                }
                sbUi.Append("  </ul>");
            }
        }
        public void TreeViewDataBing_RawMaterials(TreeView tv, string strWhere = null)
        {
            tv.Nodes.Clear();
            Catering_Rules.T_RawMaterials crr = new Catering_Rules.T_RawMaterials();
            DataSet ds_RawMaterials = crr.GetAllList();
            if (ds_RawMaterials != null)
            {
                if (ds_RawMaterials.Tables.Count > 0)
                {
                    foreach (DataRow dr_RawMaterials in ds_RawMaterials.Tables[0].Rows)
                    {
                        if (dr_RawMaterials["TypeName"] != null)
                        {
                            TreeNode tn_RawMaterials = new TreeNode();
                            tn_RawMaterials.Text = dr_RawMaterials["TypeName"].ToString();
                            tn_RawMaterials.Value = dr_RawMaterials["id"].ToString();
                            tn_RawMaterials.Target = "type";
                            //--------------添加子节点-----------------------------------//
                            TreeViewDataBing_RawMaterialsInfo(tn_RawMaterials, dr_RawMaterials["id"].ToString(), strWhere);
                            tv.Nodes.Add(tn_RawMaterials);
                        }
                    }
                }
            }

        }
        private void TreeViewDataBing_RawMaterialsInfo(TreeNode tn, string tvNodeId, string strWhere = null)
        {
            Catering_Rules.RawMaterialsInfo crr = new Catering_Rules.RawMaterialsInfo();
            DataSet ds_RawMaterialsInfo = crr.GetList("RMID=" + tvNodeId);
            if (ds_RawMaterialsInfo != null)
            {
                if (ds_RawMaterialsInfo.Tables.Count > 0)
                {
                    foreach (DataRow dr_RawMaterialsInfo in ds_RawMaterialsInfo.Tables[0].Rows)
                    {
                        if (dr_RawMaterialsInfo["Name"] != null)
                        {
                            TreeNode tn_RawMaterials = new TreeNode();
                            tn_RawMaterials.Text = dr_RawMaterialsInfo["Name"].ToString();
                            tn_RawMaterials.Value = dr_RawMaterialsInfo["id"].ToString();
                            tn_RawMaterials.Target = "typeinfo";
                            //--------------添加子节点-----------------------------------//
                            TreeViewDataBing_RawMaterial(tn_RawMaterials, dr_RawMaterialsInfo["id"].ToString(), strWhere);
                            tn.ChildNodes.Add(tn_RawMaterials);
                        }
                    }
                }
            }
        }
        private void TreeViewDataBing_RawMaterial(TreeNode tn, string strNodeId, string strWhere = null)
        {
            Catering_Rules.T_RawMaterial crr = new Catering_Rules.T_RawMaterial();
            Catering_Rules.ViewOperaction crv = new Catering_Rules.ViewOperaction();
            DataSet ds_RawMaterial = new DataSet();
            if (strWhere == null)
            {
                ds_RawMaterial = crr.GetList("RAWIDS=" + strNodeId);
            }
            else
            {
                ds_RawMaterial = crr.GetList("RAWIDS=" + strNodeId + "  and " + strWhere);
            }

            if (ds_RawMaterial != null)
            {
                if (ds_RawMaterial.Tables.Count > 0)
                {
                    foreach (DataRow dr_RawMaterial in ds_RawMaterial.Tables[0].Rows)
                    {
                        if (dr_RawMaterial["RAWName"] != null)
                        {
                            TreeNode tn_RawMaterials = new TreeNode();
                            tn_RawMaterials.Text = dr_RawMaterial["RAWName"].ToString();
                            tn_RawMaterials.Value = dr_RawMaterial["id"].ToString();
                            DataSet ds_view = crv.GetViewToDataSet("Nutrient", "[Elements]='热量' and RawID =" + dr_RawMaterial["id"].ToString());
                            if (ds_view != null)
                            {
                                if (ds_view.Tables.Count > 0)
                                {
                                    foreach (DataRow dr in ds_view.Tables[0].Rows)
                                    {
                                        tn_RawMaterials.Target = dr["Content"].ToString();

                                    }
                                }
                            }
                            tn.ChildNodes.Add(tn_RawMaterials);
                        }
                    }
                }
            }
        }
        #endregion

        #region 班组树形结构
        public void TreeViewDataBind_Group(TreeView tv)
        {
            tv.Nodes.Clear();
            Catering_Rules.OperationArea crr = new Catering_Rules.OperationArea();
            DataSet ds_OperationArea = crr.GetAllList();
            if (ds_OperationArea != null)
            {
                if (ds_OperationArea.Tables.Count > 0)
                {
                    foreach (DataRow dr_OperationArea in ds_OperationArea.Tables[0].Rows)
                    {
                        if (dr_OperationArea["AreaName"] != null)
                        {
                            TreeNode tn_RawMaterials = new TreeNode();
                            tn_RawMaterials.Text = dr_OperationArea["AreaName"].ToString();
                            tn_RawMaterials.Value = dr_OperationArea["id"].ToString();
                            tn_RawMaterials.Target = "type";
                            //--------------添加子节点-----------------------------------//
                            TreeViewDataBing_ClassInfo(tn_RawMaterials, dr_OperationArea["id"].ToString());
                            tv.Nodes.Add(tn_RawMaterials);
                        }
                    }
                }
            }
        }
        private void TreeViewDataBing_ClassInfo(TreeNode tn, string tvNodeId)
        {
            Catering_Rules.ClassInfo crr = new Catering_Rules.ClassInfo();
            DataSet ds_ClassInfo = crr.GetList("AreaID=" + tvNodeId);
            if (ds_ClassInfo != null)
            {
                if (ds_ClassInfo.Tables.Count > 0)
                {
                    foreach (DataRow dr_ClassInfo in ds_ClassInfo.Tables[0].Rows)
                    {
                        if (dr_ClassInfo["CName"] != null)
                        {
                            TreeNode tn_ClassInfo = new TreeNode();
                            tn_ClassInfo.Text = dr_ClassInfo["CName"].ToString();
                            tn_ClassInfo.Value = dr_ClassInfo["id"].ToString();
                            tn_ClassInfo.Target = "typeinfo";
                            //--------------添加子节点-----------------------------------//

                            tn.ChildNodes.Add(tn_ClassInfo);
                        }
                    }
                }
            }
        }
        #endregion
        public DataTable GetRaw(string str)
        {
            DataTable dt_Raw = new Catering_DataSet.RAW_ElementsDataTable();
            foreach (DataRow dr_Raw in dt_Raw.Rows)
            {
                dr_Raw["Re"] = GetNutrient(str, "热量");
                dr_Raw["Dan"] = GetNutrient(str, "蛋白质");
                dr_Raw["zhiF"] = GetNutrient(str, "脂肪");
                dr_Raw["HuheW"] = GetNutrient(str, "碳水化合物");
                dr_Raw["xianwei"] = GetNutrient(str, "膳食纤维");
                dr_Raw["Va"] = GetNutrient(str, "维生素A");
                dr_Raw["VB1"] = GetNutrient(str, "维生素B1");
                dr_Raw["Vb2"] = GetNutrient(str, "维生素B2");
                dr_Raw["Vbc"] = GetNutrient(str, "维生素C");
                dr_Raw["Vbe"] = GetNutrient(str, "维生素E");
                dr_Raw["dangliang"] = GetNutrient(str, "视黄醇当量");
                dr_Raw["nikesuan"] = GetNutrient(str, "尼克酸");
                dr_Raw["luobusu"] = GetNutrient(str, "胡萝卜素");

                dr_Raw["gai"] = GetNutrient(str, "钙");
                dr_Raw["lin"] = GetNutrient(str, "磷");
                dr_Raw["jia"] = GetNutrient(str, "钾");
                dr_Raw["na"] = GetNutrient(str, "钠");
                dr_Raw["mei"] = GetNutrient(str, "镁");
                dr_Raw["tie"] = GetNutrient(str, "铁");
                dr_Raw["xin"] = GetNutrient(str, "锌");
                dr_Raw["xi"] = GetNutrient(str, "硒");
                dr_Raw["tong"] = GetNutrient(str, "铜");
                dr_Raw["meng"] = GetNutrient(str, "锰");
                dr_Raw["dian"] = GetNutrient(str, "碘");

            }

            return dt_Raw;

        }
        public string GetNutrient(string RawID, string strElements)
        {
            string strNumber = string.Empty;
            Catering_Rules.ViewOperaction crvo = new Catering_Rules.ViewOperaction();
            DataSet ds_Nutrient = crvo.GetViewToDataSet("Nutrient", "RawID=" + RawID);
            if (ds_Nutrient.Tables.Count > 0)
            {
                DataRow[] drRaw = ds_Nutrient.Tables[0].Select("Elements='" + strElements + "' and RawID=" + RawID);
                strNumber = drRaw[0]["Content"].ToString();
            }
            return strNumber;
        }
        public string GetRawElement(string TypeID, string strElements)
        {
            string strNumber = string.Empty;
            Catering_Rules.NutritionElements crne = new Catering_Rules.NutritionElements();

            DataSet ds = crne.GetAllList();
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    DataTable dt_raw = ds.Tables[0];
                    DataRow[] drs = dt_raw.Select("Elements='" + strElements + "' and NutritionID=" + TypeID);
                    if (drs.Length > 0)
                    {
                        strNumber = drs[0]["id"].ToString();
                    }
                }
            }
            return strNumber;
        }

        #endregion

        #region
        public string GetMothListDay(string strYearMoth, int IntWeek)
        {
            DateTime dt = Convert.ToDateTime(strYearMoth + "-01");
            string str = dt.AddDays(Convert.ToDouble((8 - Convert.ToInt16(dt.DayOfWeek))) - 7).AddDays((IntWeek - 1) * 7).ToShortDateString();

            return str;

        }

        public void GetMothListweek(string strYearMoth, string strYearMothNext, DropDownList ddl)
        {

            DateTime dt = Convert.ToDateTime(strYearMoth + "-01");
            string str = dt.AddDays(Convert.ToDouble((8 - Convert.ToInt16(dt.DayOfWeek))) - 7).ToShortDateString();

            DateTime dtNext = Convert.ToDateTime(strYearMothNext + "-01");
            string strNext = dtNext.AddDays(Convert.ToDouble((7 - Convert.ToInt16(dtNext.AddDays(-1).DayOfWeek))) - 7).ToShortDateString();
            TimeSpan ts = Convert.ToDateTime(strNext).AddDays(7) - Convert.ToDateTime(str);
            string[] strweeks = new string[] { "第一周", "第二周", "第三周", "第四周", "第五周" };
            int day = ts.Days;
            int week = 0;
            if (day % 7 == 0)
            {
                week = day / 7;
            }
            else
            {
                week = day / 7 + 1;
            }
            for (int i = 0; i < 5; i++)
            {
                ddl.Items.Add(strweeks[i]);
            }


        }
        public void GetMothListweek(string strYearMoth, DropDownList ddl)
        {

            DateTime dttime = Convert.ToDateTime(strYearMoth + "-01");
            DateTime dtNext = dttime.AddDays(1 - dttime.Day).AddMonths(1).AddDays(-1);
            Int32 now = 7 - Convert.ToInt32(dttime.DayOfWeek);
            Int32 next = Convert.ToInt32(dtNext.DayOfWeek) - 7;

            TimeSpan ts = dtNext.AddDays(next) - dttime.AddDays(now);
            string[] strweeks = new string[] { "第一周", "第二周", "第三周", "第四周", "第五周" };
            int day = ts.Days;
            int week = 0;
            if (day % 7 == 0)
            {
                week = day / 7;
            }

            for (int i = 0; i < week + 2; i++)
            {
                ddl.Items.Add(strweeks[i]);
            }


        }


        #endregion

        #region 分页
        /// <summary>
        /// 分页绑定
        /// </summary>
        /// <param name="dt">数据</param>
        /// <param name="LocalRepeater">绑定控件</param>
        /// <param name="Request">请求对象</param>
        /// <param name="Pagesize">页面大小</param>
        /// <param name="lblCurPage">共计数</param>
        /// <param name="InkPrev">上一页</param>
        /// <param name="InkLast">首页</param>
        /// <param name="InkFirst">末叶</param>
        /// <param name="InkNext">下一页</param>
        public void RepeaterDataBind(DataTable dt, Repeater LocalRepeater, HttpRequest Request, Int32 Pagesize, Label lblCurPage, HyperLink InkPrev, HyperLink InkLast, HyperLink InkFirst, HyperLink InkNext)
        {
            PagedDataSource objPage = new PagedDataSource();
            //设置数据源 DefaultView：获取可能包含筛选视图或游标位置表的自定义视图
            objPage.DataSource = dt.DefaultView;
            //允许分页
            objPage.AllowPaging = true;
            //设置每页个数
            objPage.PageSize = Pagesize;
            //定义变量保存当前页的索引值

            int CurPage;
            //判断是否具有页面跳转的请求
            if (Request.QueryString["Page"] != null)
            {
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            }
            else
            {
                CurPage = 1;
            }
            //设置当前页的索引
            objPage.CurrentPageIndex = CurPage - 1;
            //显示状态信息
            lblCurPage.Text = "第" + CurPage.ToString() + "/" + objPage.PageCount + "页";
            //如果当前页面不是首页
            if (!objPage.IsFirstPage)
            {
                //定义“上一页”超级链接的URL为：当前执行页面的虚拟路径，并传递下一页面的索引值 
                InkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);

            }
            InkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (objPage.PageCount);
            InkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";

            //如果当前页面不是最后一页
            if (!objPage.IsLastPage)
            {
                //定义“下一页”超级链接的URL为：当前执行页面的虚拟路径，并传递下一页面的索引值 
                InkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
            }
            //将PagedDataSource作为数据源
            LocalRepeater.DataSource = objPage;

            //进行数据绑定
            LocalRepeater.DataBind();
        }

        public void RepeaterDataBind(DataTable dt, Repeater LocalRepeater, HttpRequest Request, Int32 Pagesize, Label lblCurPage, HyperLink InkPrev, HyperLink InkLast, HyperLink InkFirst, HyperLink InkNext, string url, string fileName, int pageNumber)
        {
            url = url.Remove(0, fileName.Length).Replace('?', ' ').Trim();
            string currentfilepath = Request.CurrentExecutionFilePath;
            if (currentfilepath.IndexOf('?') > 0) currentfilepath = currentfilepath.Remove(currentfilepath.IndexOf('?'));
            if (!string.IsNullOrEmpty(url)) url = currentfilepath + "?" + url; else url = currentfilepath;
            PagedDataSource objPage = new PagedDataSource();
            //设置数据源 DefaultView：获取可能包含筛选视图或游标位置表的自定义视图
            objPage.DataSource = dt.DefaultView;
            //允许分页
            objPage.AllowPaging = true;
            //设置每页个数
            objPage.PageSize = Pagesize;
            //定义变量保存当前页的索引值

            int CurPage;
            //判断是否具有页面跳转的请求
            if (pageNumber > 0)
            {
                CurPage = pageNumber;
            }
            else if (Request.QueryString["Page"] != null)
            {
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            }
            else
            {
                CurPage = 1;
            }

            //设置当前页的索引
            objPage.CurrentPageIndex = CurPage - 1;
            //显示状态信息
            lblCurPage.Text = "第" + CurPage.ToString() + "/" + objPage.PageCount + "页";
            //如果当前页面不是首页
            if (!objPage.IsFirstPage)
            {
                if (!string.IsNullOrEmpty(url) && url.IndexOf('?') > 0)
                {
                    InkPrev.NavigateUrl = url + "&Page=" + Convert.ToString(CurPage - 1);
                }
                else if (!string.IsNullOrEmpty(url))
                {
                    InkPrev.NavigateUrl = url + "?Page=" + Convert.ToString(CurPage - 1);
                }
                else
                {
                    //定义“上一页”超级链接的URL为：当前执行页面的虚拟路径，并传递下一页面的索引值 
                    InkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
                }

            }
            if (!string.IsNullOrEmpty(url) && url.IndexOf('?') > 0)
            {
                InkLast.NavigateUrl = url + "&Page=" + (objPage.PageCount);
            }
            else if (!string.IsNullOrEmpty(url))
            {
                InkLast.NavigateUrl = url + "?Page=" + (objPage.PageCount);
            }
            else
            {
                InkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (objPage.PageCount);
            }

            if (!string.IsNullOrEmpty(url) && url.IndexOf('?') > 0)
            {
                InkFirst.NavigateUrl = url + "&Page=1";
            }
            else if (!string.IsNullOrEmpty(url))
            {
                InkFirst.NavigateUrl = url + "?Page=1";
            }
            else
            {
                InkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
            }

            //如果当前页面不是最后一页
            if (!objPage.IsLastPage)
            {
                if (!string.IsNullOrEmpty(url) && url.IndexOf('?') > 0)
                {
                    InkNext.NavigateUrl = url + "&Page=" + Convert.ToString(CurPage + 1);
                }
                else if (!string.IsNullOrEmpty(url))
                {
                    InkNext.NavigateUrl = url + "?Page=" + Convert.ToString(CurPage + 1);
                }
                else
                {
                    //定义“下一页”超级链接的URL为：当前执行页面的虚拟路径，并传递下一页面的索引值 
                    InkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
                }
            }
            //将PagedDataSource作为数据源
            LocalRepeater.DataSource = objPage;

            //进行数据绑定
            LocalRepeater.DataBind();
        }

        public void RepeaterDataBind(DataTable dt, Repeater LocalRepeater)
        {
            PagedDataSource objPage = new PagedDataSource();
            //设置数据源 DefaultView：获取可能包含筛选视图或游标位置表的自定义视图
            objPage.DataSource = dt.DefaultView;
            //允许分页
            objPage.AllowPaging = false;

            //定义变量保存当前页的索引值

            //将PagedDataSource作为数据源
            LocalRepeater.DataSource = objPage;

            //进行数据绑定
            LocalRepeater.DataBind();
        }
        #endregion

        #region 寻找ＩＤ
        public Int32 GetRawID(string strGroupID, string strRawID)
        {
            Int32 RowID = 0;
            string str = "AreaID=" + strGroupID + " and InDBid='" + strRawID + "'";
            RowID = new Catering_Rules.ViewOperaction().GetSingle("RawMaterial_Area", "RawID", str);
            Catering_Model.E_RawMaterial cmrm = new Catering_Rules.T_RawMaterial().GetModel(RowID);
            if (cmrm != null)
            {
                return RowID;
            }
            else
            {
                return 0;
            }
        }
        #endregion

    }
}